package com.stu.config;

import com.stu.interceptor.JwtAuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 拦截器配置 (Spring Boot 3.x 兼容版)
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private JwtAuthInterceptor jwtAuthInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 需要拦截的路径
        String[] protectedPaths = {
                "/getAllOrders/**",      // 订单相关
                "/spikeProduct/goConfirm", // 秒杀
                "/testPerson",           // 个人中心
                "/coupon/selectCoupon/**", // 优惠券
                "/cart/**"               // 购物车
        };

        // 排除的路径（如登录、公开API）
        String[] excludePaths = {
                "/auth/login",
                "/public/**"
        };

        registry.addInterceptor(jwtAuthInterceptor)
                .addPathPatterns(protectedPaths)
                .excludePathPatterns(excludePaths)
                .order(1); // 设置拦截器执行顺序
    }
}